/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Company: </p> 
 * @author 王校兵
 * @date 2016年7月19日
 */
package com.artpri.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.artpri.dao.IndexPagePictureDao;
import com.artpri.model.AdNews;
import com.artpri.model.AdPicture;

/**
 * IndexPagePictureDao实现类
 * 
 * @author 王校兵
 * @date 2016年7月19日
 * @version 1.0
 */
@Repository
public class IndexPagePictureDaoImpl extends HibernateDaoImpl<AdPicture>
		implements IndexPagePictureDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<AdPicture> getIndexPicture(String page, String fromPosition,
			String toPosition) {

		System.out.println(getSessionFactory().getCurrentSession());

		List<AdPicture> asd = getSessionFactory().getCurrentSession().createSQLQuery(
						"select * from ad_picture ap where ap.ap_page_name='001' and ap.ap_position_name "
								+ " between '0010001' and '0010006' and ap_state = '1'  union select * from ad_picture ap where ap.ap_page_name=? "
								+ " and ap.ap_position_name between ? and ?")
				.addEntity(AdPicture.class).setParameter(0, page)
				.setParameter(1, fromPosition).setParameter(2, toPosition)
				.list();

		return asd;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<AdPicture> getIndexPictureAndProduct(String page,
			String fromPosition, String toPosition) {

		return getSessionFactory()
				.getCurrentSession()
				.createSQLQuery(
						" select ap.ap_path, ap.an_alt, ap.ap_url, g.goods_name, g.goods_price, count(*) "
								+ " from (ad_picture ap left outer join goods g on (g.goods_num = ap.ap_good_num) ) "
								+ " left outer join goods_comment gc on(ap.ap_good_num = gc.goods_num) "
								+ "where  ap.ap_page_name = ? "
								+ " and ap.ap_position_name between ? and ? and ap_state = '1' group by ap.ap_position_name")
				.setParameter(0, page).setParameter(1, fromPosition)
				.setParameter(2, toPosition).list();
	}

}
